﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Osg;
using ZFGK.Addins;
using ZFGK.OSG.UI;
using ZFGK.OSG.Utility;
using ZFGK.Utility;

namespace OSS.ModelViewer.Commands.TestCmds
{
    public class TestLineCmd : IExtendCommand
    {
        public CmdResult Execute(ExtendCmdData cmdData, ref string message)
        {
            var viewForm = cmdData.ViewForm as IViewForm;
            var osgView = viewForm.View as IOsgViewCtrl;
            var osgObj = osgView.OsgObj;

            var random = new Random();
            var normal = new Vec3f(0, 0, 1);
            var stateSet = new StateSet();
            stateSet.SetLighting(false);

            var list = new List<Node>();
            for (int i = 0; i < 10000; i++)
            {
                float x1 = (float) random.NextDouble() * 10000;
                float y1 = (float) random.NextDouble() * 10000;
                float z1 = (float) random.NextDouble() * 10000;
                float x2 = (float) random.NextDouble() * 10000;
                float y2 = (float) random.NextDouble() * 10000;
                float z2 = (float) random.NextDouble() * 10000;

                float x3 = (float) random.NextDouble();
                float y3 = (float) random.NextDouble();
                float z3 = (float) random.NextDouble();

                var geode = OsgGeometryUtil.CreateLine(new[] {new Vec3f(x1, y1, z1), new Vec3f(x2, y2, z2)},
                    normal, new Vec4f(x3, y3, z3, 1)).CreateGeode();
                geode.Name = i.ToString();
                geode.setStateSet(stateSet);
                list.Add(geode);
                if (list.Count == 50)
                {
                    ZfUiProgressUtil.SetProgress(i + 1, 10000);
                    osgObj.AddOrReplaceModel("Test", list);
                    list = new List<Node>();
                }
            }
            ZfUiProgressUtil.ClearProgress();
            return CmdResult.Succeed;
        }
    }
}
